package com.dx_society.controller;

import com.dx_society.dto.Result;
import com.dx_society.service.ActivitiesService;
import com.dx_society.service.ActivityCommentService;
import com.dx_society.service.ActivityMemberService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/ac")
public class ActivityController {
    @Resource
    private ActivitiesService activitiesService;
    @Resource
    private ActivityMemberService activityMemberService;

    @Resource
    private ActivityCommentService activityCommentService;
    /**
     * 查询活动列表
     * @param ac_name 活动名称（非必填）
     * @param so_id 社团id（非必填）
     * @param orderRole 排序方式 0：字典序 1：参与数降序 2：时间升序 3：综测分降序
     * @param isValid 是否在有效期内（默认是）
     * @return 活动列表
     */
    @GetMapping(value = "/list")
    public Result queryActivitiesList(
            @RequestParam(value = "ac_name", required = false) String ac_name,
            @RequestParam(value = "so_id", required = false) Long so_id,
            @RequestParam(value = "order", defaultValue = "0") Integer orderRole,
            @RequestParam(value = "is_valid", defaultValue = "true") Boolean isValid
    ) {
        return activitiesService.queryActivitiesList(ac_name, so_id, orderRole, isValid);
    }

    /**
     * 获取活动详情
     * @param id 活动id
     * @return 活动详情
     */
    @GetMapping(value = "/detail/{id}")
    public Result queryActivitiesDetail(@PathVariable("id") Long id) {
        return activitiesService.queryActivityDetail(id);
    }

    /**
     * 报名活动
     * @param id 活动id
     * @return 报名结果
     */
    @PostMapping(value = "/join/{id}")
    public Result joinActivities(@PathVariable("id") Long id) {
        return activityMemberService.joinActivities(id);
    }

    /**
     * 签到活动
     * @param id 活动id
     * @param signCode 签到码
     * @return 签到结果
     */
    @GetMapping(value = "/sign/{id}")
    public Result signActivities(@PathVariable("id") Long id, @RequestParam("sign") String signCode, @RequestParam("userId") Long userId) {
        return activityMemberService.signActivities(id,signCode,userId);
    }

    /**
     * 创建签到
     * @param id 活动id
     * @return 签到码和签到二维码路径
     */
    @PostMapping(value = "/create_sign/{id}")
    public Result createSignInfo(@PathVariable("id") Long id) {
        return activitiesService.createSignInfo(id);
    }

    /**
     * 发送评论
     * @param id 活动id
     * @param comment 评论内容
     * @return 发送结果
     */
    @PostMapping(value = "/sendComment/{id}")
    public Result sendComment(@PathVariable("id") Long id, @RequestParam("comment") String comment) {
        return activityCommentService.sendComment(id, comment);
    }

    /**
     * 查询评论
     * @param id 活动id
     * @return 评论列表
     */
    @GetMapping(value = "/comment/{id}")
    public Result queryComment(@PathVariable("id") Long id) {
        return activityCommentService.queryComment(id);
    }

    /**
     * 查询我的活动列表
     * @param state 活动状态 0：已报名 1：已参加
     * @return 活动列表
     */
    @GetMapping(value ="/my/list")
    public Result queryMyActivitiesList(@RequestParam("state") Integer state) {
        return activityMemberService.queryMyActivitiesList(state);
    }
}
